package com.example.imoocmusicdemo.activitys;

import android.content.DialogInterface;
import android.content.Intent;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

import com.example.imoocmusicdemo.R;

public class MainActivity2 extends BaseActivity {

    private ImageView iv1, iv2, iv1Like, iv1Talking, iv2Like, iv2Talking, iv3Like, iv3Talking, iv4Like, iv4Talking, iv5Like, iv5Talking;

    @Override
    protected void onCreate(Bundle savedInstanceState) {


        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);

        iv1Like = findViewById(R.id.iv1_like);
        iv1Talking = findViewById(R.id.iv1_talking);
        iv2Like = findViewById(R.id.iv2_like);
        iv2Talking = findViewById(R.id.iv2_talking);
        iv3Like = findViewById(R.id.iv3_like);
        iv3Talking = findViewById(R.id.iv3_talking);
        iv4Like = findViewById(R.id.iv4_like);
        iv4Talking = findViewById(R.id.iv4_talking);
        iv5Like = findViewById(R.id.iv5_like);
        iv5Talking = findViewById(R.id.iv5_talking);

        iv1Talking.setOnClickListener(listener2);
        iv2Talking.setOnClickListener(listener2);
        iv3Talking.setOnClickListener(listener2);
        iv4Talking.setOnClickListener(listener2);
        iv5Talking.setOnClickListener(listener2);

        iv1Like.setOnClickListener(new View.OnClickListener() {
            int i = 1;
            @Override
            public void onClick(View view) {
                i += 1;
                if (i % 2 == 0) {
                    iv1Like.setImageResource(R.mipmap.liked);
                } else {
                    iv1Like.setImageResource(R.mipmap.nolike);
                }

            }
        });

        iv2Like.setOnClickListener(new View.OnClickListener() {
            int i = 1;
            @Override
            public void onClick(View view) {
                i += 1;
                if (i % 2 == 0) {
                    iv2Like.setImageResource(R.mipmap.liked);
                } else {
                    iv2Like.setImageResource(R.mipmap.nolike);
                }

            }
        });

        iv3Like.setOnClickListener(new View.OnClickListener() {
            int i = 1;
            @Override
            public void onClick(View view) {
                i += 1;
                if (i % 2 == 0) {
                    iv3Like.setImageResource(R.mipmap.liked);
                } else {
                    iv3Like.setImageResource(R.mipmap.nolike);
                }

            }
        });

        iv4Like.setOnClickListener(new View.OnClickListener() {
            int i = 1;
            @Override
            public void onClick(View view) {
                i += 1;
                if (i % 2 == 0) {
                    iv4Like.setImageResource(R.mipmap.liked);
                } else {
                    iv4Like.setImageResource(R.mipmap.nolike);
                }

            }
        });

        iv5Like.setOnClickListener(new View.OnClickListener() {
            int i = 1;
            @Override
            public void onClick(View view) {
                i += 1;
                if (i % 2 == 0) {
                    iv5Like.setImageResource(R.mipmap.liked);
                } else {
                    iv5Like.setImageResource(R.mipmap.nolike);
                }

            }
        });

        init();
        iv1OnClick();
        iv2OnClick();

    }

    View.OnClickListener listener2 = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            switch (view.getId()){
                case R.id.iv1_talking:
                    AlertDialog alertDialog = new AlertDialog.Builder(MainActivity2.this).create();
                    alertDialog.setIcon(R.drawable.question);
                    alertDialog.setTitle("    ");
                    alertDialog.setMessage("         评论点什么呢？");
                    final EditText editText = new EditText(MainActivity2.this);
                    alertDialog.setView(editText);
                    alertDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "评论", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Toast.makeText(MainActivity2.this, "评论完成", Toast.LENGTH_SHORT).show();
                        }
                    });
                    alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, "取消", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Toast.makeText(MainActivity2.this, "你选择了取消", Toast.LENGTH_SHORT).show();
                        }
                    });
                    alertDialog.show();
                    break;
                case R.id.iv2_talking:
                    iv2Like.setImageResource(R.mipmap.liked);
                    AlertDialog alertDialog2 = new AlertDialog.Builder(MainActivity2.this).create();
                    alertDialog2.setIcon(R.drawable.question);
                    alertDialog2.setTitle("    ");
                    alertDialog2.setMessage("         评论点什么呢？");
                    final EditText editText2 = new EditText(MainActivity2.this);
                    alertDialog2.setView(editText2);
                    alertDialog2.setButton(DialogInterface.BUTTON_NEGATIVE, "评论", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Toast.makeText(MainActivity2.this, "评论完成", Toast.LENGTH_SHORT).show();
                        }
                    });
                    alertDialog2.setButton(DialogInterface.BUTTON_POSITIVE, "取消", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Toast.makeText(MainActivity2.this, "你选择了取消", Toast.LENGTH_SHORT).show();
                        }
                    });
                    alertDialog2.show();
                    break;
                case R.id.iv3_talking:
                    iv3Like.setImageResource(R.mipmap.liked);
                    AlertDialog alertDialog3 = new AlertDialog.Builder(MainActivity2.this).create();
                    alertDialog3.setIcon(R.drawable.question);
                    alertDialog3.setTitle("    ");
                    alertDialog3.setMessage("         评论点什么呢？");
                    final EditText editText3 = new EditText(MainActivity2.this);
                    alertDialog3.setView(editText3);
                    alertDialog3.setButton(DialogInterface.BUTTON_NEGATIVE, "评论", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Toast.makeText(MainActivity2.this, "评论完成", Toast.LENGTH_SHORT).show();
                        }
                    });
                    alertDialog3.setButton(DialogInterface.BUTTON_POSITIVE, "取消", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Toast.makeText(MainActivity2.this, "你选择了取消", Toast.LENGTH_SHORT).show();
                        }
                    });
                    alertDialog3.show();
                    break;
                case R.id.iv4_talking:
                    iv4Like.setImageResource(R.mipmap.liked);
                    AlertDialog alertDialog4 = new AlertDialog.Builder(MainActivity2.this).create();
                    alertDialog4.setIcon(R.drawable.question);
                    alertDialog4.setTitle("    ");
                    alertDialog4.setMessage("         评论点什么呢？");
                    final EditText editText4 = new EditText(MainActivity2.this);
                    alertDialog4.setView(editText4);
                    alertDialog4.setButton(DialogInterface.BUTTON_NEGATIVE, "评论", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Toast.makeText(MainActivity2.this, "评论完成", Toast.LENGTH_SHORT).show();
                        }
                    });
                    alertDialog4.setButton(DialogInterface.BUTTON_POSITIVE, "取消", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Toast.makeText(MainActivity2.this, "你选择了取消", Toast.LENGTH_SHORT).show();
                        }
                    });
                    alertDialog4.show();
                    break;
                case R.id.iv5_talking:
                    iv5Like.setImageResource(R.mipmap.liked);
                    AlertDialog alertDialog5 = new AlertDialog.Builder(MainActivity2.this).create();
                    alertDialog5.setIcon(R.drawable.question);
                    alertDialog5.setTitle("    ");
                    alertDialog5.setMessage("         评论点什么呢？");
                    final EditText editText5 = new EditText(MainActivity2.this);
                    alertDialog5.setView(editText5);
                    alertDialog5.setButton(DialogInterface.BUTTON_NEGATIVE, "评论", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Toast.makeText(MainActivity2.this, "评论完成", Toast.LENGTH_SHORT).show();
                        }
                    });
                    alertDialog5.setButton(DialogInterface.BUTTON_POSITIVE, "取消", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Toast.makeText(MainActivity2.this, "你选择了取消", Toast.LENGTH_SHORT).show();
                        }
                    });
                    alertDialog5.show();
                    break;
            }
        }
    };

    private void iv1OnClick() {
        iv1 = fd(R.id.image1);
        iv1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent i = new Intent(MainActivity2.this, MainActivity.class);
                startActivity(i);
                finish();
            }
        });
    }

    private void iv2OnClick() {
        iv2 = fd(R.id.image2);
        iv2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(getApplicationContext(), "您已经在当前页面了", Toast.LENGTH_SHORT).show();
            }
        });
    }

    private void init() {
        initNavBar(false, "emo云村", false);
    }
}